package springboot.user.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springboot.common.Result;
import springboot.user.model.User;
import springboot.user.service.UserService;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins="*")
public class UserController {

	@Resource
	private UserService userService;
	
	@RequestMapping("/getUser")
	public Result getUser() {
		return Result.success(userService.getUser());
	}
	
	@RequestMapping("/addUser")
	public Result addUser(User user) {
		userService.addUser(user);
		return Result.success();
	}
	
	@RequestMapping("/updateUser")
	public Result updateUser(User user) {
		userService.updateUser(user);
		return Result.success();
	}
	
	@RequestMapping("/deleteUser")
	public Result deleteUser(String id) {
		userService.deleteUser(Integer.valueOf(id));
		return Result.success();
	}
	
	@RequestMapping("/getUserById")
	public Result getUserById(String id) {
		return Result.success(userService.getUserById(Integer.valueOf(id)));
	}
	
	@RequestMapping("/getUserByUsernameAndName")
	public Result getUserByUsernameAndName(String username,String name) {
		return Result.success(userService.getUserByUsernameAndName(username, name));
	}
	
}
